From 0d5bbbf750427d5783de4836c969f254d76185e3 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Tue, 27 Apr 1993 22:01:32 +0000 Subject: [PATCH] (hscroll-step): New variable. (hscroll-point-visible): New function. (left-arrow, right-arrow): These use hscroll-point-visible for better auto- scrolling behavior. --- lisp/simple.el | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/lisp/simple.el b/lisp/simple.el index 3731fbebb13..3196eee32b3 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -1387,28 +1387,47 @@ The goal column is stored in the variable `goal-column'." goal-column)) nil) +;;; Partial support for horizontal autoscrolling. Someday, this feature +;;; will be built into the C level and all the (hscroll-point-visible) calls +;;; will go away. + +(defvar hscroll-step 0 + "*The number of columns to try scrolling a window by when point moves out. +If that fails to bring point back on frame, point is centered instead. +If this is zero, point is always centered after it moves off frame.") + +(defun hscroll-point-visible () + "Scrolls the window horizontally to make point visible." + (let* ((min (window-hscroll)) + (max (- (+ min (window-width)) 2)) + (here (current-column)) + (delta (if (zerop hscroll-step) (/ (window-width) 2) hscroll-step)) + ) + (if (< here min) + (scroll-right (max 0 (+ (- min here) delta))) + (if (>= here max) + (scroll-left (- (- here min) delta)) + )))) + ;;; Make arrow keys do the right thing for improved terminal support ;;; When we implement true horizontal autoscrolling, right-arrow and ;;; left-arrow can lose the (if truncate-lines ...) clause and become -;;; aliases. +;;; aliases. These functions are bound to the corresponding keyboard +;;; events in loaddefs.el. (defun right-arrow (arg) "Move right one character on the screen (with prefix ARG, that many chars). Scroll right if needed to keep point horizontally onscreen." (interactive "P") (forward-char arg) - (if truncate-lines - (let ((x (current-column)) (w (- (window-width) 2))) - (set-window-hscroll (selected-window) (- x (% x w)) )))) + (hscroll-point-visible)) (defun left-arrow (arg) "Move left one character on the screen (with prefix ARG, that many chars). Scroll left if needed to keep point horizontally onscreen." (interactive "P") (backward-char arg) - (if truncate-lines - (let ((x (current-column)) (w (- (window-width) 2))) - (set-window-hscroll (selected-window) (- x (% x w)) )))) + (hscroll-point-visible)) (defun down-arrow (arg) "Move down one line on the screen (with prefix ARG, that many lines). -- 2.30.2